package com.twu.biblioteca;

import java.io.*;

public class Mainclass extends Library
{
    static int ch;
    public static void main(String arg[])  throws IOException
    {
        int op;
        String uname="",password;
        Boolean chk_login=false;
        Library Lib=new Library();
        DataInputStream Din= new DataInputStream(System.in);
        do
        {
        System.out.println("****WELCOME TO BANGALORE PUBLIC LIBRARY****");         //To get the choice from the user
        System.out.println("Select an option");
        System.out.println("1.View Books in the Library");
        System.out.println("2.Reserve a Book");
        System.out.println("3.View Membership Details");
        System.out.println("4.View List of Movies");

        String s1=Din.readLine();
        ch=Integer.parseInt(s1);
                 switch(ch)
        {
            case 1:
                Lib.view_books();                            //Fn Call To view books in the library
                break;
            case 2:
                if(!chk_login)
                {

                System.out.println("UNAME:");
                uname=Din.readLine();
                System.out.println("PASSWORD:");
                password=Din.readLine();
                chk_login=Lib.Authenticate_user(uname,password);
                }
                 if(chk_login)
                 {
                    System.out.println("Enter Book ID");
                    String s2=Din.readLine();
                    int bid=Integer.parseInt(s2);
                    boolean flag=Lib.is_bookavailable(bid);       //Fn call to check if the particular book is available
                    if(flag)
                    {
                        System.out.println("Book reserved");
                    }
                    else
                    {
                        System.out.println("Sorry book not available");
                    }
                }
                else
                {
                    System.out.println("Enter Correct Uname and Password");
                }
                break;
            case 3:

                  if(chk_login)
                  {
                  Lib .view_details(uname);                      //Fn call to view the membership details
                  }
                  else
                  {
                      System.out.println("Please talk to Librarian...Thank You");
                  }

                  break;
            case 4:
                  Lib.view_movies();
                  break;
            default:
                System.out.println("Enter valid option");
          }

        System.out.println("\nEnter 1 to continue");
        String s3=Din.readLine();
        op=Integer.parseInt(s3);
        }while(op==1);



    }
}
